package com.ruoyi.project.para.smActXrt.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.para.smActXrt.domain.SmActXrt;
import com.ruoyi.project.para.smActXrt.service.ISmActXrtService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 汇率Controller
 *
 * @author gang.wei
 * @date 2020-04-07
 */
@Controller
@RequestMapping("/para/smActXrt")
public class SmActXrtController extends BaseController
{
    private String prefix = "para/smActXrt";

    @Autowired
    private ISmActXrtService smActXrtService;

    @RequiresPermissions("para:smActXrt:view")
    @GetMapping()
    public String smActXrt()
    {
        return prefix + "/smActXrt";
    }

    /**
     * 查询汇率列表
     */
    @RequiresPermissions("para:smActXrt:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SmActXrt smActXrt)
    {
        startPage();
        List<SmActXrt> list = smActXrtService.list(new QueryWrapper<>(smActXrt));
        return getDataTable(list);
    }

    /**
     * 导出汇率列表
     */
    @RequiresPermissions("para:smActXrt:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SmActXrt smActXrt)
    {
        List<SmActXrt> list = smActXrtService.list(new QueryWrapper<>(smActXrt));
        ExcelUtil<SmActXrt> util = new ExcelUtil<SmActXrt>(SmActXrt.class);
        return util.exportExcel(list, "smActXrt");
    }

    /**
     * 新增汇率
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存汇率
     */
    @RequiresPermissions("para:smActXrt:add")
    @Log(title = "汇率", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SmActXrt smActXrt)
    {
        return toAjax(smActXrtService.saveOrUpdate(smActXrt));
    }

    /**
     * 修改汇率
     */
    @GetMapping("/edit/{primaryKey}")
    public String edit(@PathVariable("primaryKey") String primaryKey, ModelMap mmap)
    {
        SmActXrt smActXrt = smActXrtService.getById(primaryKey);
        mmap.put("smActXrt", smActXrt);
        return prefix + "/edit";
    }

    /**
     * 修改保存汇率
     */
    @RequiresPermissions("para:smActXrt:edit")
    @Log(title = "汇率", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SmActXrt smActXrt)
    {
        return toAjax(smActXrtService.saveOrUpdate(smActXrt));
    }

    /**
     * 删除汇率
     */
    @RequiresPermissions("para:smActXrt:remove")
    @Log(title = "汇率", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(smActXrtService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
